package weaver.interfaces.suntai.action;

import com.alibaba.fastjson.JSONObject;
import com.weaver.general.BaseBean;
import com.weaver.general.Util;
import weaver.conn.RecordSet;
import weaver.interfaces.suntai.utils.InvokeHelper;
import weaver.interfaces.workflow.action.Action;
import weaver.soa.workflow.request.RequestInfo;

/**
 * @Title: ecology-idea
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2022-05-12
 * @Description: 采购合同申请流程
 * @ModifyLog:
 **/

public class WeaIncomeContractAction extends BaseBean implements Action {

    @Override
    public String execute(RequestInfo requestInfo) {
        String requestid = requestInfo.getRequestid();
        String tablename = requestInfo.getRequestManager().getBillTableName();
        String resultText = "";
        RecordSet rs = new RecordSet();
        writeLog( ">>>>>>WeaIncomeContractAction>>>>>" + requestid );
        try {
            rs.executeQuery( "select * from " + tablename + " where requestid=?", requestid );
            if (rs.next()) {
                JSONObject jsonData = new JSONObject();
                //企业编号
                jsonData.put( "companyCode", Util.null2String( rs.getString( "qybh" ) ));
                //合同编号
                jsonData.put( "contractCode", Util.null2String( rs.getString( "htbh" ) ) );
                //收入金额
                jsonData.put( "incomeAmount", Util.null2String( rs.getString( "srje" ) ) );
                //收入日期
                jsonData.put( "incomeDate", Util.null2String( rs.getString( "kprq" ) ) );
                //创建人
                jsonData.put( "createBy", Util.null2String( rs.getString( "sqrdxwb" ) ) );
                //租户编码
                jsonData.put( "tenantCode", Util.null2String( rs.getString( "zhbm" ) ) );
                //状态
                jsonData.put( "status", "rkz" );
                writeLog( ">>>>>jsonData>>>>>" + jsonData.toJSONString() );
                resultText = InvokeHelper.addIncomecont( jsonData.toJSONString() );
                writeLog( ">>>>>resultText>>>>>" + resultText );
                JSONObject resultJson = JSONObject.parseObject( resultText );
                String code = Util.null2String( resultJson.getString( "code" ) );
                String message = Util.null2String( resultJson.getString( "message" ) );
                if (!"200".equals( code )) {
                    requestInfo.getRequestManager().setMessageid( "111111" );
                    requestInfo.getRequestManager().setMessagecontent( "接口返回异常信息：" + message );
                    return Action.FAILURE_AND_CONTINUE;
                }
            }
            return Action.SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            requestInfo.getRequestManager().setMessageid( "111111" );
            requestInfo.getRequestManager().setMessagecontent( "Action接口异常！" );
            return Action.FAILURE_AND_CONTINUE;
        }

    }
}
